package com.payment.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.payment.common.base.AjaxResult;
import com.payment.common.page.TableDataInfo;
import com.payment.common.utils.ExcelUtil;
import com.payment.framework.web.base.BaseController;
import com.payment.system.domain.Register;
import com.payment.system.service.IRegisterService;

/**
 * 网站用户 信息操作处理
 * 
 * @author payment
 * @date 2020-01-06
 */
@Controller
@RequestMapping("/system/register")
public class RegisterController extends BaseController
{
    private String prefix = "system/register";
	
	@Autowired
	private IRegisterService registerService;
	
	@RequiresPermissions("system:register:view")
	@GetMapping()
	public String register()
	{
	    return prefix + "/register";
	}
	
	/**
	 * 查询网站用户列表
	 */
	@RequiresPermissions("system:register:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Register register)
	{
		startPage();
        List<Register> list = registerService.selectRegisterList(register);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出网站用户列表
	 */
	@RequiresPermissions("system:register:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Register register)
    {
    	List<Register> list = registerService.selectRegisterList(register);
        ExcelUtil<Register> util = new ExcelUtil<Register>(Register.class);
        return util.exportExcel(list, "register");
    }
	
	/**
	 * 新增网站用户
	 */
/*	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	*/
	/**
	 * 新增保存网站用户
	 */
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Register register)
	{		
		return toAjax(registerService.insertRegister(register));
	}

	/**
	 * 修改网站用户
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Register register = registerService.selectRegisterById(id);
		mmap.put("register", register);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存网站用户
	 */
	@RequiresPermissions("system:register:edit")
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Register register)
	{		
		return toAjax(registerService.updateRegister(register));
	}
	
	/**
	 * 删除网站用户
	 */
	@RequiresPermissions("system:register:remove")
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(registerService.deleteRegisterByIds(ids));
	}
	
}
